package org.javaexpert.concurrent;

/**
 * Created by IntelliJ IDEA.
 * User: piotrga
 * Date: Dec 18, 2007
 * Time: 3:48:21 PM
 * To change this template use File | Settings | File Templates.
 */
public class Box<T> {
    private T content;

    public synchronized void put(T content){
        this.content = content;
        this.notifyAll();
    }

    public synchronized T remove(){
        while(content == null){
            niceWait();
        }
        T tmp = content;
        content = null;
        return tmp;
    }

    private void niceWait() {
        try {
            wait();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}
